<template>
  <!-- 工人培训版块 -->
  <div class="training">
    <div class="header">
      <p class="title">工人培训版块</p>
    </div>
    <div class="display">
      <div class="item">
        <p class="val">
          <span class="icon1"></span>
          <count-to
            :startVal="0"
            :endVal="trainCount"
            :duration="1000"
            class="num"
          ></count-to>
        </p>
        <p class="key">累计培训(人次)</p>
      </div>
      <span class="line"></span>
      <div class="item">
        <p class="val">
          <span class="icon2"></span>
          <count-to
            :startVal="0"
            :endVal="holdCount"
            :duration="1000"
            class="num"
          ></count-to>
        </p>
        <p class="key">颁发电子证件(本)</p>
      </div>
      <span class="line"></span>
      <div class="item">
        <p class="val">
          <span class="icon3"></span>
          <count-to
            :startVal="0"
            :endVal="trainPlanCount"
            :duration="1000"
            class="num"
          ></count-to>
        </p>
        <p class="key">累计开展培训(场)</p>
      </div>
    </div>
    <div class="chart-wrap">
      <Echart
        id="traning-chart"
        :options="option"
        height="214px"
        width="100%"
      />
      <div class="legend"><span class="color"></span> 平台累积人数</div>
    </div>
  </div>
</template>

<script setup>
import { onMounted, reactive, ref } from "vue";
import Echart from "@/components/echart/index.vue";
import CountTo from "@/components/vueCountTo/vue-countTo.vue";
import { ajax } from "@/store/service";
import { dataGroup } from "@/utils";
import opt from "./trainingSectionOpt";

const trainCount = ref(0);
const holdCount = ref(0);
const trainPlanCount = ref(0);

const option = reactive({ ...opt });

const init = async () => {
  const [res] = await ajax.training();
  trainCount.value=res.trainCount
  holdCount.value=res.holdCount
  trainPlanCount.value=res.trainPlanCount
  let chart = dataGroup(res.chart);
  option.xAxis.data = chart.x;
  option.series[0].data = chart.y;
  option.series[1].data = chart.y;
};

onMounted(() => {
  init();
});
</script>

<style scoped lang='scss'>
.training {
  width: 548px;
  height: 408px;
  .header {
    width: 100%;
    height: 80px;
    background: url("@/assets/longscreen2/title-short.png");
    background-size: 100%;
    padding-top: 15px;
    box-sizing: border-box;
    .title {
      font-size: 22px;
      font-family: JLinXin;
      font-weight: 600;
      line-height: 22px;
      background: #fffde8 linear-gradient(180deg, #e8feff 40%, #00a9ff 100%);
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
      margin-left: 73px;
      font-weight: bold;
    }
  }
  .display {
    margin-bottom: 38px;
    box-sizing: border-box;
    padding-left: 30px;
    padding-right: 30px;
    padding-top: 17px;
    display: flex;
    justify-content: space-between;
    .item {
      // width: 143px;
      height: 59px;
      // border: #00a9ff 1px solid;
      .val {
        display: flex;
        margin-bottom: 8px;
        .icon1 {
          display: block;
          height: 30px;
          width: 30px;
          background: url("@/assets/longscreen2/icon_累计培训.png");
        }
        .icon2 {
          display: block;
          height: 30px;
          width: 30px;
          background: url("@/assets/longscreen2/icon_颁发电子证件.png");
        }
        .icon3 {
          display: block;
          height: 30px;
          width: 30px;
          background: url("@/assets/longscreen2/icon_累计开展培训.png");
        }
        .num {
          font-size: 26px;
          font-family: D-DIN-PRO-Heavy, D-DIN-PRO;
          font-weight: bold;
          color: #ffffff;
          line-height: 32px;
          margin-left: 12px;
          white-space: nowrap;
          overflow: hidden;
          display: inline;
        }
      }
      .key {
        font-size: 18px;
        font-family: SourceHanSansCN-Medium, SourceHanSansCN;
        font-weight: 500;
        color: #ffffff;
        line-height: 27px;
        opacity: 0.7;
      }
    }
    .line {
      display: block;
      width: 1px;
      height: 52px;
      background: linear-gradient(
        180deg,
        rgba(9, 217, 242, 0) 0%,
        #09d7f0 51%,
        rgba(9, 214, 239, 0) 100%
      );
    }
  }
  .chart-wrap {
    width: 503px;
    height: 214px;
    margin: 0 auto;
    // border: #00a9ff 1px solid;
    position: relative;
    .legend {
      position: absolute;
      top: -10px;
      right: 0;
      font-size: 14px;
      font-family: SourceHanSansCN-Regular, SourceHanSansCN;
      font-weight: 400;
      color: #fffde8;
      line-height: 21px;
      display: flex;
      align-items: center;
      .color {
        width: 16px;
        height: 6px;
        background: #00f9d1;
        display: block;
        margin-right: 6px;
      }
    }
  }
}
</style>